

********************************************************
*Title: REStat-20513_DATA_figure.do
*Date: 10 June, 2019
*Author: Li Liu, Tim Schmidt-Eisenlhor, Dongxian Guo
********************************************************


*********Figure 1. Tax Incentives for Profit Shifting******************

*Panel (a). Distribution of Tax Differential

qui use "${hmrc_datadir}\export_reg_final_ukmncs_fy_ntrans", clear

gen tax_differential=tax-uk_tax
histogram tax_differential, width(1) xtitle("Tax Differential (%)") frac ///
ytitle("Fraction of Transactions") graphregion(fcolor(white)) 

graph save "${hmrc_graphdir}\figure1a_historam_taxwedge.gph", replace
graph export "${hmrc_graphdir}\figure1a_historam_taxwedge.png", replace
	
*Panel (b). Time Variation in Tax Differential


use  "${hmrc_datadir}\graph_taxchange.dta", clear
drop uk_rate

drop if year<2005 | year>2011

ren cit_comb_uk uk_rate

gen tax_wedge=abs(uk_rate-cit_comb)

gen I_low=cit_comb<uk_rate
gen I_high=cit_comb>uk_rate

drop if I_low==0 & I_high==0

xtset ccode year

gen t_change=tax_wedge!=l.tax_wedge

gen obs=1

collapse (sum)obs t_change, by (year I_low I_high)

gen t_change_frac=t_change/obs


#delimit ;
graph twoway (scatter t_change year if year>=2006 & I_low==1, sort mcolor(dkgreen) msymbol(oh))
(scatter t_change year if year>=2006 & I_high==1, sort mcolor(red) msymbol(Th)) 
, 
ytitle("Number of Countries") ylabel()
legend (order(1 "Low-tax" 2 "High-tax" ) 
rows(1) position(11) ring(0))
xtitle("Year") xlabel(2006(1)2011) graphregion(fcolor(white)) 
;
#delimit cr

graph save Graph "${hmrc_graphdir}\figure1b_tchange.gph", replace
graph export "${hmrc_graphdir}\figure1b_tchange.png", replace

****Figure 2. Effect sizes in the literature; drawn in excel without using any HMRC data******


**********Figure 3. Log Unit Price Residuals and the Tax Reform****************

qui use "${hmrc_datadir}\export_reg_final_ukmncs_fy", clear

*post-reform variables
gen post=year>=2009
gen r_lowwedge_post=r_lowwedge*post
gen r_highwedge_post=r_highwedge*post
gen r_post=related*post
*controls
gen gdppc_usd=gdppc/exchange_rate
sum gdppc_usd
gen lgdppc=ln(gdppc_usd)
gen related_lnGDP=related*lgdppc

global outcome lnp_weight

gen cat1=""
replace cat1="related_lowtax" if low_tax_country==1 & related==1
replace cat1="related_hightax" if high_tax_country==1 & related==1
replace cat1="nonrelated_lowtax" if low_tax_country==1 & related==0
replace cat1="nonrelated_hightax" if high_tax_country==1 & related==0

gen ones=1

reghdfe ${outcome} r_lowwedge r_highwedge related_lnGDP r_post if year!=2009 , absorb(i.identifier#i.comcode#i.ctry ///
i.year#i.identifier#i.comcode i.year#i.ctry#i.comcode) resid(lnp_resid) vce(cluster ctry_year)

#delimit ;
graph twoway (scatter lnp_resid year if cat1=="related_lowtax" & year!=2009, sort msymbol(plus))
(scatter lnp_resid year if cat1=="nonrelated_lowtax" & year!=2009, sort msymbol(circle)),
ytitle("Average Log Unit Price Residual: Low-Tax") ylabel(-0.02(0.01)0.02)
xtitle("Year") xlabel(2005(1)2011) graphregion(fcolor(white))
legend (order(1 "Related Party" 2 "Arm's Length" ) rows(1) position(1) ring(0))
;
#delimit cr

graph save "${hmrc_graphdir}\figure3a_logpresidual_mean_lowtax", replace
graph export "${hmrc_graphdir}\figure3a_logpresidual_mean_lowtax.png", replace

#delimit ;
graph twoway (scatter lnp_resid year if cat1=="related_lowtax" & year!=2009, sort msymbol(plus))
(scatter lnp_resid year if cat1=="related_hightax" & year!=2009, sort msymbol(triangle)),
ytitle("Average Log Unit Price Residual: Related Party") ylabel(-0.02(0.01)0.02)
xtitle("Year") xlabel(2005(1)2011) graphregion(fcolor(white))
legend (order(1 "Low-Tax" 2 "High-Tax" ) rows(1) position(1) ring(0))
;
#delimit cr

graph save "${hmrc_graphdir}\figure3b_logpresidual_mean_related", replace
graph export "${hmrc_graphdir}\figure3b_logpresidual_mean_related.png", replace

********Figure 4. Non-linear transfer mispricing in low-tax countries************


*quintile of country-level tax differential*
qui use "${hmrc_datadir}\export_reg_final_ukmncs_fy", clear
keep if low_tax_country==1

xtset id year

*controls
gen gdppc_usd=gdppc/exchange_rate
sum gdppc_usd
gen lgdppc=ln(gdppc_usd)
gen related_lnGDP=related*lgdppc

global outcome lnp_weight

estimates clear

****By Tax Wedge Quintile****

cap drop tax_wedge
gen tax_wedge=abs(tax-uk_tax) 

global q=5
xtile tw_d=tax_wedge if low_tax_country==1, n($q)
qui tab tw_d if low_tax_country==1, ge(tw_d)

forv i=1/$q {
qui gen tax_wedge_d`i'=tax_wedge*tw_d`i' if low_tax_country==1
qui gen r_wedge_d`i'=related*tax_wedge_d`i' if low_tax_country==1
}


estimates clear

*full sample
eststo: reghdfe ${outcome} r_wedge_d1-r_wedge_d5 , ///
absorb(i.identifier#i.comcode#i.ctry i.year#i.identifier#i.comcode i.year#i.ctry#i.comcode) vce(cluster ctry_year)


eststo: reghdfe ${outcome} r_wedge_d1-r_wedge_d$q related_lnGDP, ///
absorb(i.identifier#i.comcode#i.ctry i.year#i.identifier#i.comcode i.year#i.ctry#i.comcode) vce(cluster ctry_year)

*Haven
eststo: reghdfe ${outcome} r_wedge_d1-r_wedge_d$q related_lnGDP if tax_haven==1, ///
absorb(i.identifier#i.comcode#i.ctry i.year#i.identifier#i.comcode i.year#i.ctry#i.comcode) vce(cluster ctry_year)

*Non-tax Haven
eststo: reghdfe ${outcome} r_wedge_d1-r_wedge_d$q related_lnGDP if tax_haven==0, ///
absorb(i.identifier#i.comcode#i.ctry i.year#i.identifier#i.comcode i.year#i.ctry#i.comcode) vce(cluster ctry_year)

estout est* using "${hmrc_resultdir}\regression_lowtax_quintile.xls", ///
cells(b(star fmt(%9.3f)) se(par(`"("'`")"'))) ///
starlevels(* 0.10 ** 0.05 *** 0.01) stats(r2 r2_a N , ///
fmt(%9.3f %9.0g) labels(R-squared))  label replace 

qui insheet using "${hmrc_datadir}\tax_quartile.csv", clear   /*dataset record coefficient and standard errors in "regression_lowtax_quintile.xls", for the full sample*/
qui gen b_min95=bhat-1.64*bhat_std
qui gen b_max95=bhat+1.64*bhat_std


#delimit ;

twoway (scatter bhat tax_quartile, mcolor(black) msymbol(circle) msize(small))
(rcap b_min95 b_max95 tax_quartile, lcolor(black))
(scatter freq_citchange tax_quartile1, sort yaxis(2) mcolor(blue) msymbol(diamond) msize(small)
mlabel(freq_citchange) mlabposition(12)), 
legend(off)
xlabel(, valuelabels angle(0) labsize(vsmall)) 
ylabel(0(0.2)0.8,axis(2))  ytitle("Estimated Tax Coefficient") 
yline(0, lcolor(red))
ytitle("Fraction of Countries with Rate Changes", axis(2)) 
xtitle("Tax Wedge Quintile in Low-Tax Countries") graphregion(fcolor(white) margin(l+10 r+10))
;
#delimit cr

graph save "${hmrc_graphdir}\figure4a_tax_quintile", replace
graph export "${hmrc_graphdir}\figure4atax_quintile.png", replace


*Haven vs Non-Haven*

qui insheet using "${hmrc_datadir}\tax_quintile_bygroup.csv", clear  /*dataset record coefficient and standard errors in "regression_lowtax_quintile.xls", by haven and non-havens*/

qui gen b_min95=bhat-1.64*bhat_std
qui gen b_max95=bhat+1.64*bhat_std


#delimit ;

twoway (scatter bhat tax_wedge if haven==1 , mcolor(blue) msymbol(circle) msize(small))
(rcap b_min95 b_max95 tax_wedge if haven==1, lcolor(blue))
(scatter bhat tax_wedge if haven==0 , mcolor(orange) msymbol(triangle) msize(small))
(rcap b_min95 b_max95 tax_wedge if haven==0, lcolor(orange) lpattern(dash))
, 
legend(order(1 "Haven" 2 "" 3 "Non-Tax Haven" 4 "") rows(1) position(11) ring(0))
xlabel(, valuelabels angle(0) labsize(vsmall)) 
ytitle("Estimated Tax Coefficient") 
yline(0, lcolor(red) lwidth(vthin))
xtitle("Tax Wedge in Low-Tax Countries") graphregion(fcolor(white) margin(l+10 r+10))
;
#delimit cr

graph save "${hmrc_graphdir}\figure4b_tax_quintile_bygroup", replace
graph export "${hmrc_graphdir}\figure4b_tax_quintile_bygroup.png", replace


clear
exit
